//serve static files(html,json,image) using HTTP and file system module

//1.load a HTML file
const http = require('http');
const fs = require('fs');
http.createServer((req,res)=>{
    const readStream = fs.createReadStream('./9.Static Folder/UTSHelps_Student/UtsHelpsHome.html');
    res.writeHead(200,{'Content-type':'text/html'});//http 200 means the request has been successfully completed.
    readStream.pipe(res);
}).listen(3000);

//2.load a json file
const http2 = require('http');
const fs2 = require('fs');
http2.createServer((req,res)=>{
    const readStream2 = fs2.createReadStream('./9.Static Folder/example.json');
    res.writeHead(200,{'Content-type':'application/json'});
    readStream2.pipe(res);
}).listen(3000);

//3.load an image
const http3 = require('http');
const fs3 = require('fs');
http3.createServer((req,res)=>{
    const readStream3 = fs3.createReadStream('./9.Static Folder/example.png');
    res.writeHead(200,{'Content-type':'image/png'});
    readStream3.pipe(res);
}).listen(3000);